const { Sequelize, DataTypes } = require('sequelize');

const sequelize = new Sequelize('mysql://root:root@127.0.0.1:3306/iai') 
// Option 2: Passing parameters separately (sqlite)
// const sequelize = new Sequelize({
//   dialect: 'sqlite',
//   storage: 'path/to/database.sqlite'
// });

// // Option 3: Passing parameters separately (other dialects)
// const sequelize = new Sequelize('database', 'username', 'password', {
//   host: 'localhost',
//   dialect: /* one of 'mysql' | 'postgres' | 'sqlite' | 'mariadb' | 'mssql' | 'db2' | 'snowflake' | 'oracle' */
// });

const Article = sequelize.define(
  'fa_article',
  {
    // Model attributes are defined here
    id: {
      type: DataTypes.INTEGER,
      autoIncrement: true,
      primaryKey: true,
    },
    title: {
      type: DataTypes.STRING,
      // allowNull defaults to true
    },
    content: {
      type: DataTypes.TEXT,
      // allowNull defaults to true
    },
  },
);

console.log(sequelize.models.fa_article); // true
console.log(Article === sequelize.models.fa_article); // true

Article.findAll().then(articles => {
  console.log(articles);
}
).catch(err => {
  console.error('Unable to connect to the database:', err);
});


// sequelize.sync({ force: true }).then(() => {
//   console.log('Database & tables created!');
// }).catch(err => {
//   console.error('Unable to connect to the database:', err);
// });
